#!/usr/bin/env bash
project_path=$(cd `dirname $0`; cd .. ; pwd;)
cd $project_path || exit
echoRed() {
    echo "\033[31m $1 \033[0m"
}

echo 'ceshi ------------------------------'

echoText() {
    echo '------------------------------'
    echo $1
    echo '------------------------------'
    echo ''
}

branch_name=$1

#更新代码
echoText '切换 $branch_name 分支'

projects="../MarsCarWorkspace MarsCar MarsCar_Flutter MarsCar_IM MarsCar_Kit MarsCar_Login MarsCar_Mediator MarsCar_Mine MarsCar_Stocktake"

for project in $projects
do
    cd $project_path && cd $project || exit

    echoRed "还原 $project 分支代码"
    git checkout .  || exit
    git clean -df  || exit
    
    echoRed "切换 $project 分支"
    git remote update origin --prune || exit
    git checkout $branch_name || exit
    git checkout .  || exit
    git pull  || exit
    
    echo ""
done

echo '----------'
echo 切换分支完毕
echo '----------'
echo ''

